//-----------------------------------------------------------------------
// <copyright file="DeleteFtpSite.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
// </copyright>
// <author>Mark Phillips</author>
// <email>andyr</email>
// <date>2004-03-23</date>
// <summary>Deletes the specified FtpSite.</summary>
//-----------------------------------------------------------------------

namespace Microsoft.Sdc.Tasks.Web.FtpSite
{
    using System;
    using System.Xml;
    using System.Globalization;
    using System.Net;
    using Microsoft.Sdc.Tasks.Configuration.Web;
    using Microsoft.Build.Framework;

    /// <summary>
    /// Deletes an ftp site from the local server
    /// </summary>
    /// <remarks>
    /// <code><![CDATA[<Web.FtpSite.DeleteFtpSite 
    ///     Description="description" 
    ///     Identifier="identifier"
    /// >]]></code>
    /// <para>where:</para>
    /// <para><i>description</i></para>
    /// <para>A description for the web site</para>
    /// <para><i>identifier</i></para>
    /// <para>Any valid ftp site identifier</para>
    /// <para><b>Either a <i>description</i> or an <i>identifier</i> must be specified.</b></para>
    /// </remarks>
    /// <example>
    /// <code><![CDATA[
    /// <Project>
    ///     <Target Name="Test" >
    ///         <Web.FtpSite.DeleteFtpSite Description="testftpsite" />
    ///     </Target>
    /// </Project>
    /// ]]></code>    
    /// </example>    
    public class DeleteFtpSite : TaskBase
    {

        private string description;
        private string identifier;
        private int id;

        /// <summary>
        /// Performs the action of this task.
        /// </summary>
        protected override void InternalExecute()
        {
            #region Execute code
            if (this.Description.Length == 0 && this.Identifier.Length == 0)
            {
                throw new TaskException("Web.DescriptionOrIdentifier");
            }
            if (this.Description.Length > 0 && this.Identifier.Length > 0)
            {
                throw new TaskException("Web.DescriptionOrIdentifierNotBoth", description, identifier);
            }
            id = Utilities.CheckFtpSiteDescriptionOrIdentifier(this.Description, this.Identifier, "Deleting");
            if (FtpSite.Exists(id))
            {
                FtpSite.Delete(id);
            }
            #endregion
        }

        /// <summary>
        /// Description of ftp site to delete
        /// </summary>
        /// <value>A valid ftp site description</value>
        /// <remarks>If this parameter is not specified you must specify the site <seealso cref="Identifier">Identifier</seealso> 
        /// for the site you wish to delete</remarks>
        public string Description
        {
            get
            {
                return (description == null ? String.Empty : description);
            }
            set
            {
                description = value;
            }
        }

        /// <summary>
        /// ftp site idenfitier to delete
        /// </summary>
        /// <value>A valid ftp site identifier</value>
        /// <remarks>If this parameter is not specified you must specify the site <seealso cref="Description">Description</seealso> 
        /// for the site you wish to delete</remarks>
        public string Identifier
        {
            get
            {
                return (identifier == null ? String.Empty : identifier);
            }
            set
            {
                identifier = value;
            }
        }
    }
}